package com.example.pages;

import static org.openqa.selenium.support.ui.ExpectedConditions.alertIsPresent;

import java.util.List;

import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;

public class InternalPage extends AnyPage {

	//Home link
	@FindBy(xpath = "//nav//li[1]/a")
	public WebElement menuHomeLink;
	
	//My profile link
	@FindBy(xpath = "//nav//li[2]/a")
	public WebElement menuMyProfileLink;
	
	//User management link
	@FindBy(xpath = "//li[3]/a")
	public WebElement menuUserManagementLink;
	
	//Log out link
	@FindBy(xpath = "//li[4]/a")
	public WebElement menuLogoutLink;
	
	@FindBy(xpath = "//div[@id='results']/a")
	public List<WebElement> linksToFilms;
	
	
	public boolean isOnThisPage(){
		
		return menuLogoutLink.isDisplayed();
		
	}
	
	public void logout() {
		menuLogoutLink.click();
	    wait_().until(alertIsPresent()).accept();
	}

	@Override
	void tryToOpen() {
		MyPageFactory.getPage(driver, LoginPage.class).loginWithValidCredentials("admin","admin");
		
	}

	public UserManagementPage goToUserManagement() {
		menuUserManagementLink.click();
		return MyPageFactory.getPage(driver, UserManagementPage.class);
	}
	
	public UserPage goToMyProfile() {
		menuMyProfileLink.click();
		return MyPageFactory.getPage(driver, UserPage.class);
    }
	
	public FilmsPage goToFilmsPage() {
		menuHomeLink.click();
		return MyPageFactory.getPage(driver, FilmsPage.class);
	}	
		
}
